home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / stdwin / Packs / vt / vtvtrm.c < prev   
Encoding:
C/C++ Source or Header  |  1991-05-14  |  2.7 KB  |  143 lines  |  [TEXT/????]

  1. /* VTRM implementation using VT as lower layer.
  2.    Unfortunately, this isn't too useful on the input part:
  3.    you'll really want to use wgetevent directly to get access
  4.    to mouse clicks, menu events etc.
  5.    Another problem is that there is no portable way to direct normal
  6.    output (e.g., from printf and putchar) to the VTRM window.
  7.    One other thing: you'll have to call wdone() when you really exit. */
  8.  
  9. /* XXX This has never been tested... */
  10. /* XXX The interfaces to trmputdata and trmsense should change !!! */
  11.  
  12. #include "vtimpl.h"
  13. #include "vtrm.h"
  14.  
  15. static VT *vt;
  16. static bool active;
  17.  
  18. int
  19. trmstart(rows_return, cols_return, flags_return)
  20.     int *rows_return, *cols_return, *flags_return;
  21. {
  22.     if (active)
  23.         return TE_TWICE; /* Already started */
  24.     if (vt == NULL) {
  25.         winit();
  26.         wsetdefwinsize(24*wcharwidth('0'), 80*wlineheight());
  27.         vt= vtopen("VTRM", 24, 80, 0);
  28.         if (vt == NULL)
  29.             return TE_NOMEM; /* Failure */
  30.     }
  31.     *rows_return= 24;
  32.     *cols_return= 80;
  33.     *flags_return=
  34.         HAS_STANDOUT | CAN_SCROLL;
  35.     return TE_OK;
  36. }
  37.  
  38. trmend()
  39. {
  40.     active= FALSE;
  41. }
  42.  
  43. /* XXX Need interface change */
  44. trmputdata(row, col, data)
  45.     int row, col;
  46.     char *data;
  47. {
  48.     char *start= data;
  49.     int mask= 0;
  50.     vtsetcursor(vt, row, col);
  51.     do {
  52.         if ((*data & 0x80) != mask) {
  53.             if (data > start) {
  54.                 if (mask) {
  55.                     char *p;
  56.                     for (p= start; p < data; ++p)
  57.                         *p &= 0x7f;
  58.                     vt->gflags= VT_INVERSE;
  59.                 }
  60.                 vtputstring(vt, start, data-start);
  61.                 if (mask) {
  62.                     char *p;
  63.                     for (p= start; p < data; ++p)
  64.                         *p |= 0x80;
  65.                     vt->gflags= 0;
  66.                 }
  67.                 start= data;
  68.             }
  69.             mask= *data & 0x80;
  70.         }
  71.     } while (*data++ != EOS);
  72.     /* XXX This is likely to omit the final data? */
  73.     vteolclear(vt, vt->cur_row, vt->cur_col);
  74. }
  75.  
  76. trmscrollup(r1, r2, n)
  77.     int r1, r2;
  78.     int n;
  79. {
  80.     if (n > 0)
  81.         vtscrollup(vt, r1, r2+1, n);
  82.     else if (n < 0)
  83.         vtscrolldown(vt, r1, r2+1, -n);
  84. }
  85.  
  86. trmsync(row, col)
  87.     int row, col;
  88. {
  89.     vtsetcursor(vt, row, col);
  90. }
  91.  
  92. static lasth, lastv;
  93.  
  94. int
  95. trminput()
  96. {
  97.     EVENT e;
  98.     for (;;) {
  99.         switch (e.type) {
  100.         case WE_COMMAND:
  101.             switch (e.type) {
  102.             case WC_CANCEL:
  103.                 return '\003';
  104.             case WC_RETURN:
  105.                 return '\r';
  106.             case WC_TAB:
  107.                 return '\t';
  108.             case WC_BACKSPACE:
  109.                 return '\b';
  110.             case WC_LEFT:
  111.                 return '\034';
  112.             case WC_RIGHT:
  113.                 return '\035';
  114.             case WC_UP:
  115.                 return '\036';
  116.             case WC_DOWN:
  117.                 return '\037';
  118.             }
  119.             break;
  120.         case WE_CHAR:
  121.             return e.u.character;
  122.             break;
  123.         case WE_MOUSE_DOWN:
  124.         case WE_MOUSE_MOVE:
  125.         case WE_MOUSE_UP:
  126.             lasth= e.u.where.h;
  127.             lastv= e.u.where.v;
  128.             if (e.type == WE_MOUSE_UP)
  129.                 return '\007';
  130.             break;
  131.         }
  132.     }
  133. }
  134.  
  135. /* XXX Need interface change */
  136. int
  137. trmsense(row_return, col_return)
  138.     int *row_return, *col_return;
  139. {
  140.     *row_return= lastv / vtcheight(vt);
  141.     *col_return= lasth / vtcwidth(vt);
  142. }
  143.